<?php

namespace App\Http\Controllers\Dash;

use App\Http\Controllers\Controller;
use App\Model\Contato;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Crypt;

class ContatoController extends Controller
{
    public function index()
    {

        $data = Contato::all()->reject(function ($data) {
            return $data->status == 'resolved';
        });

        return view('dash.contato.index', compact('data'));
    }

    public function read($id)
    {
        $data = Contato::find($id);
        return view('dash.contato.read', compact('id', 'data'));
    }

    public function comment($id, Request $request)
    {
        $contato = Contato::find($id);
        $contato->comment = $request->comment;
        $contato->status = $request->status;
        $contato->save();
        return redirect()->route('dash.contato')->with('error', compact('contato'));
    }

    public function delete($id)
    {
        $data = Contato::find($id)->delete();
        return redirect()->route('dash.contato')->with('error', compact('data'));
    }

}
